package com.nifostasky.comic.controller;

import com.nifostasky.comic.entitys.SysDict;
import com.nifostasky.comic.entitys.SysDictDomain;
import com.nifostasky.comic.service.SysDictService;
import com.nifostasky.comic.utils.PageUtils;
import com.nifostasky.comic.vos.JsonResult;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sysDict")
@Api(tags = "数据字典小类")
@ApiSort(8)
@AllArgsConstructor
public class SysDictController {
    private SysDictService sysDictService;

    @ApiOperation(value = "分页列表",notes = "带参分页查询列表")
    @GetMapping("findListPage")
    @ApiOperationSupport(order = 1)
    public JsonResult findListPage(PageUtils pageUtils, SysDict sysDict){
        return new JsonResult(sysDictService.findListPage(pageUtils, sysDict));
    }

    @ApiOperation(value = "分页列表",notes = "带参分页查询列表")
    @GetMapping("findList")
    @ApiOperationSupport(order = 2)
    public JsonResult findList(SysDict sysDict){
        return new JsonResult(sysDictService.findList(sysDict));
    }

    @ApiOperation("新增/修改")
    @PostMapping("/saveOrUpdate")
    @ApiOperationSupport(order = 3)
    public JsonResult saveOrUpdate(@RequestBody SysDict sysDict){
        return new JsonResult(sysDictService.saveOrUpdateData(sysDict));
    }

    @ApiOperation("根据主键id获取信息")
    @GetMapping("/getData")
    @ApiResponses(@ApiResponse(code = 200,message = "返回成功",response = SysDict.class))
    @ApiImplicitParams(
            @ApiImplicitParam(name = "id", value = "主键id", dataType = "Int",required = true)
    )
    @ApiOperationSupport(order = 4)
    public JsonResult<SysDictDomain> getData(Long id){
        return new JsonResult(sysDictService.getById(id));
    }

    @ApiOperation("单个或批量删除")
    @GetMapping("/deleteByIds")
    @ApiOperationSupport(order = 5)
    public JsonResult deleteByIds(@ApiParam("主键ids，批量删除时id用英文逗号隔开数据格式:id1,id2,id3,...") String ids){
        return new JsonResult(sysDictService.deleteByIds(ids));
    }

    @ApiOperation("根据大类code获取字典信息")
    @GetMapping("/findDataListByDomainCode")
    @ApiOperationSupport(order = 6)
    public JsonResult findDataListByDomainCode(@ApiParam("大类code") String domainCode){
        return new JsonResult(sysDictService.findDataListByDomainCode(domainCode));
    }
    @ApiOperation("根据多个大类code获取字典信息，不传条件获取所有")
    @GetMapping("/findDataListAllByDomainCode")
    @ApiOperationSupport(order = 7)
    public JsonResult findDataListAllByDomainCode(@ApiParam("大类code:格式:id1,id2,id3,...") String domainCodeStr){
        return new JsonResult(sysDictService.findDataListAllByDomainCode(domainCodeStr));
    }
}
